package net.projects.pro5_rss.reader;

import net.projects.pro5_rss.Buffer.NewsBuffer;
import net.projects.pro5_rss.bean.CommonInformationItem;
import net.projects.pro5_rss.bean.RSSDataCapturer;
import org.apache.log4j.Logger;

import java.util.List;

public class NewsProductTask implements Runnable{
    private NewsBuffer buffer;
    private String name;
    private String url;

    private static final Logger logger = Logger.getLogger(NewsProductTask.class);

    public NewsProductTask(NewsBuffer buffer, String name, String url) {
        this.buffer = buffer;
        this.name = name;
        this.url = url;
    }

    @Override
    public void run() {
        RSSDataCapturer capturer = new RSSDataCapturer(name);
        List<CommonInformationItem> list = capturer.load(url);
        for (CommonInformationItem item : list) {
            buffer.addItem(item);
        }
        logger.info("新闻源：" + name + "  新闻数量：" + list.size()+"  路径  "+url+"下载完成");
    }
}
